Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.getDomContent = void 0);
var e = require("../../../@babel/runtime/helpers/objectSpread2"),
  t = n(require("./parser")),
  r = n(require("@/libs/lodash"));
function n(e) {
  return e && e.__esModule ? e : { default: e };
}
exports.getDomContent = function (e) {
  var r = (0, t.default)(e),
    n = a(r);
  return 1 === n.length && "p" === n[0].type && (n = n[0].val), n;
};
var a = function (t) {
    var n = [];
    return (
      (function t(a) {
        for (
          var u = function () {
              var u = a[i],
                o = l(u);
              if (
                (o && n.push(o),
                "p" === o.type ||
                  "ul" === o.type ||
                  "ol" === o.type ||
                  "blockquote" === o.type ||
                  "img" === o.type ||
                  "card" === o.type ||
                  "audio" === o.type ||
                  "video" === o.type ||
                  !u.children ||
                  !u.children.length)
              )
                return 1;
              var d = ["strong", "i", "s"],
                c = u.children.map(function (t) {
                  var n =
                      -1 !== d.indexOf(u.name)
                        ? u.name
                        : r.default.get(u, "parentName", ""),
                    a = r.default.get(u, "attrs", {});
                  return e(e({}, t), {}, { parentName: n, parentAttr: a });
                });
              t(c);
            },
            i = 0;
          i < a.length;
          i++
        )
          u();
      })(t),
      n
    );
  },
  l = function (e) {
    return "p" === e.name
      ? g(e)
      : "br" === e.name
        ? { type: "br" }
        : "text" === e.type
          ? u(e)
          : "exeditor-picture" === r.default.get(e, "attrs.class", "")
            ? c(e)
            : "video" === r.default.get(e, "name", "")
              ? s(e)
              : "audio" === r.default.get(e, "name", "")
                ? h(e)
                : "ul" === e.name
                  ? i(e)
                  : "ol" === e.name
                    ? o(e)
                    : "blockquote" === e.name
                      ? d(e)
                      : "hr" === e.name
                        ? { type: "hr" }
                        : "app-editor-card" ===
                            r.default.get(e, "attrs.class", "")
                          ? f(e)
                          : "";
  },
  u = function (e) {
    var t = { type: "text", val: e.text || "", style: "" };
    return (
      "strong" === e.parentName && (t.style += "font-weight: bold;"),
      "i" === e.parentName && (t.style += "font-style: italic;"),
      "s" === e.parentName && (t.style += "text-decoration: line-through;"),
      (t.style += r.default.get(e, "parentAttr.style", "")),
      (t.style += r.default.get(e, "attrs.style", "")),
      t
    );
  },
  i = function (e) {
    for (
      var t = { type: "ul", val: [] }, n = [], l = 0;
      l < e.children.length;
      l++
    )
      "li" === r.default.get(e.children[l], "name", "") &&
        n.push(r.default.get(e.children[l], "children", []));
    for (var u = 0; u < n.length; u++) {
      var i = a(n[u]);
      t.val.push(i);
    }
    return t;
  },
  o = function (e) {
    for (
      var t = { type: "ol", val: [] }, n = [], l = 0;
      l < e.children.length;
      l++
    )
      "li" === r.default.get(e.children[l], "name", "") &&
        n.push(r.default.get(e.children[l], "children", []));
    for (var u = 0; u < n.length; u++) {
      var i = a(n[u]);
      t.val.push(i);
    }
    return t;
  },
  d = function (e) {
    return { type: "blockquote", val: a(r.default.get(e, "children", [])) };
  },
  c = function (e) {
    var t = { type: "img", src: "" };
    return (
      (function e(n) {
        for (var a = 0; a < n.length; a++) {
          if ("img" === n[a].name && r.default.get(n[a], "attrs.src", "")) {
            t.src = r.default.get(n[a], "attrs.src", "");
            break;
          }
          n[a].children && n[a].children.length > 0 && e(n[a].children);
        }
      })(e.children),
      t
    );
  },
  f = function (e) {
    return { type: "card", val: r.default.get(e, "attrs", {}) };
  },
  p = function (e) {
    for (
      var t = e || 32,
        r = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
        n = r.length,
        a = "",
        l = 0;
      l < t;
      l++
    )
      a += r.charAt(Math.floor(Math.random() * n));
    return a;
  },
  s = function (t) {
    return {
      type: "video",
      val: e(
        e({}, r.default.get(t, "attrs", {})),
        {},
        { id: p(10), statePlay: !1, duration: "" },
      ),
    };
  },
  h = function (e) {
    return { type: "audio", val: r.default.get(e, "attrs", {}) };
  },
  g = function (e) {
    return { type: "p", val: a(r.default.get(e, "children", [])) };
  };
